/**
 * Copyright © 2015 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */
package com.eqxiu.ieditor.api.impl;

import com.eqxiu.ieditor.api.ISceneTagServiceApi;
import com.eqxiu.ieditor.dao.SceneTagMapper;
import com.eqxiu.ieditor.dto.SceneTagDTO;
import com.eqxiu.ieditor.entity.SceneTag;
import com.eqxiu.ieditor.entity.SceneTagExample;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @description //TODO 设计说明
 * @author ranger
 * @date Jun 1, 2017
 */
@Service
public class SceneTagServiceApiImpl implements ISceneTagServiceApi {

	@Autowired
	private SceneTagMapper sceneTagMapper;

	@Override
	public long countByExample(Integer tagId) {
		SceneTagExample example = new SceneTagExample();
		example.createCriteria().andTagIdEqualTo(tagId);
		return sceneTagMapper.countByExample(example);
	}

	@Override
	public int deleteByPrimaryKey(Long sceneId) {
		return sceneTagMapper.deleteByPrimaryKey(sceneId);
	}

	@Override
	public int insert(SceneTagDTO record) {
		SceneTag tag = new SceneTag();
		BeanUtils.copyProperties(record, tag);

		return sceneTagMapper.insert(tag);
	}

	@Override
	public int insertSelective(SceneTagDTO record) {
		SceneTag tag = new SceneTag();
		BeanUtils.copyProperties(record, tag);

		return sceneTagMapper.insertSelective(tag);
	}

	@Override
	public List<SceneTagDTO> selectByTagId(Integer tagId) {
		SceneTagExample example = new SceneTagExample();
		example.createCriteria().andTagIdEqualTo(tagId);
		List<SceneTag> tags = sceneTagMapper.selectByExample(example);
		List<SceneTagDTO> dtos = Lists.newArrayList();
		for (SceneTag tag:tags){
			SceneTagDTO dto = new SceneTagDTO();
			BeanUtils.copyProperties(tag, dto);
			dtos.add(dto);
		}
		return dtos;
	}

	@Override
	public SceneTagDTO selectByPrimaryKey(Long sceneId) {
		SceneTag one = sceneTagMapper.selectByPrimaryKey(sceneId);
		SceneTagDTO dto = new SceneTagDTO();
		BeanUtils.copyProperties(one, dto);
		return dto;
	}

}
